/*******************************************************************************
  Name: stdint.h
  Copyright: Kieran Foot 2009
  Author: Kieran Foot
  Date: 13/06/09 18:43
  Description: Standard integer type definitions
*******************************************************************************/

#include <_ansi.h>
#include <MGOS.h>
#include <limits.h>

#ifndef __STDINT_H__
#define __STDINT_H__

_BEGIN_STD_C

typedef signed char		            int8_t;
typedef short 		                int16_t;
typedef int			                int32_t;
typedef long long   	            int64_t;

typedef unsigned char		        uint8_t;
typedef unsigned short int		    uint16_t;
typedef unsigned int			    uint32_t;
typedef unsigned long long   	    uint64_t;

typedef signed char		            int_least8_t;
typedef short 		                int_least16_t;
typedef int			                int_least32_t;
typedef long long                   int_least64_t;

typedef unsigned char	            uint_least8_t;
typedef unsigned short              uint_least16_t;
typedef unsigned int	            uint_least32_t;
typedef unsigned long long          uint_least64_t;

typedef signed char		            int_fast8_t;
typedef int			                int_fast16_t;
typedef int			                int_fast32_t;
typedef long long int		        int_fast64_t;

typedef unsigned char               uint_fast8_t;
typedef unsigned int	            uint_fast16_t;
typedef unsigned int	            uint_fast32_t;
typedef unsigned long long int      uint_fast64_t;

#if MGOS_TARGET_BITS == 32
    typedef long                    intptr_t
    typedef unsigned long           uintptr_t
#elif MGOS_TARGET_BITS == 64
    typedef long long               intptr_t
    typedef unsigned long long      uintptr_t
#endif

typedef long long int		        intmax_t;
typedef unsigned long long          uintmax_t;

#if !defined __cplusplus || defined __STDC_LIMIT_MACROS

    #define __INT64_C(c)	        c ## LL
    #define __UINT64_C(c)	        c ## ULL
    
    #define INT8_MIN		        SCHAR_MIN
    #define INT16_MIN		        SHRT_MIN
    #define INT32_MIN		        INT_MIN
    #define INT64_MIN		        LLONG_MIN
    
    #define INT8_MAX		        SCHAR_MAX
    #define INT16_MAX		        SHRT_MAX
    #define INT32_MAX		        INT_MAX
    #define INT64_MAX		        LLONG_MAX
    
    #define UINT8_MAX		        UCHAR_MAX
    #define UINT16_MAX		        USHRT_MAX
    #define UINT32_MAX		        UINT_MAX
    #define UINT64_MAX		        ULLONG_MAX
    
    #define INT_LEAST8_MIN		    SCHAR_MIN
    #define INT_LEAST16_MIN	        SHRT_MIN
    #define INT_LEAST32_MIN	        INT_MIN
    #define INT_LEAST64_MIN	        LLONG_MIN
    
    #define INT_LEAST8_MAX		    SCHAR_MAX
    #define INT_LEAST16_MAX	        SHRT_MAX
    #define INT_LEAST32_MAX	        INT_MAX
    #define INT_LEAST64_MAX	        LLONG_MAX
    
    #define UINT_LEAST8_MAX		    UCHAR_MAX
    #define UINT_LEAST16_MAX	    USHRT_MAX
    #define UINT_LEAST32_MAX	    UINT_MAX
    #define UINT_LEAST64_MAX	    ULLONG_MAX
    
    #define INT_FAST8_MIN           SCHAR_MIN
    #define INT_FAST16_MIN          SHRT_MIN
    #define INT_FAST32_MIN          INT_MIN
    #define INT_FAST64_MIN          LLONG_MIN
    
    #define INT_FAST8_MAX           SCHAR_MAX
    #define INT_FAST16_MAX          SHRT_MAX
    #define INT_FAST32_MAX          INT_MAX
    #define INT_FAST64_MAX          LLONG_MAX
    
    #define UINT_FAST8_MAX          UCHAR_MAX
    #define UINT_FAST16_MAX         USHRT_MAX
    #define UINT_FAST32_MAX         UINT_MAX
    #define UINT_FAST64_MAX         ULLONG_MAX 
 
    #if MGOS_TARGET_BITS == 32
        #define INTPTR_MIN		    INT_MIN
        #define INTPTR_MAX		    INT_MAX
        #define UINTPTR_MAX		    UINT_MAX
    #elif MGOS_TARGET_BITS == 64
        #define INTPTR_MIN		    LONG_MIN
        #define INTPTR_MAX		    LONG_MAX
        #define UINTPTR_MAX		    ULONG_MAX
    #endif
    
    #define INTMAX_MIN              LLONG_MAX
    #define INTMAX_MAX              LLONG_MIN
    #define UINTMAX_MAX             ULLONG_MAX
    
    #if MGOS_TARGET_BITS == 32
        #define PTRDIFF_MIN		    INT_MIN
        #define PTRDIFF_MAX         INT_MAX
    #elif MGOS_TARGET_BITS == 64
        #define PTRDIFF_MIN		    LONG_MIN
        #define PTRDIFF_MAX         LONG_MAX    
    #endif
    
    #if MGOS_TARGET_BITS == 32   
        #define SIZE_MAX            UINT_MAX
    #elif MGOS_TARGET_BITS == 64
        #define SIZE_MAX            UINT_MAX
    #endif
    
    #if MGOS_WIDE_CHAR_SIZE == 8
        #define WCHAR_MIN		    SCHAR_MIN
        #define WCHAR_MAX           SCHAR_MAX
    #elif MGOS_WIDE_CHAR_SIZE == 16
        #define WCHAR_MIN		    SHRT_MIN
        #define WCHAR_MAX           SHRT_MAX    
    #elif MGOS_WIDE_CHAR_SIZE == 24
        #define WCHAR_MIN		    INT_MIN
        #define WCHAR_MAX           INT_MAX
    #elif MGOS_WIDE_CHAR_SIZE == 32
        #define WCHAR_MIN		    INT_MIN
        #define WCHAR_MAX           INT_MAX
    #elif MGOS_WIDE_CHAR_SIZE == 40
        #define WCHAR_MIN		    LLONG_MIN
        #define WCHAR_MAX           LLONG_MAX
    #elif MGOS_WIDE_CHAR_SIZE == 48
        #define WCHAR_MIN		    LLONG_MIN
        #define WCHAR_MAX           LLONG_MAX
    #elif MGOS_WIDE_CHAR_SIZE == 56
        #define WCHAR_MIN		    LLONG_MIN
        #define WCHAR_MAX           LLONG_MAX
    #elif MGOS_WIDE_CHAR_SIZE == 62
        #define WCHAR_MIN		    LLONG_MIN
        #define WCHAR_MAX           LLONG_MAX
    #endif
    
#endif

#if !defined __cplusplus || defined __STDC_CONSTANT_MACROS

    #define INT8_C(c)	            c
    #define INT16_C(c)	            c
    #define INT32_C(c)	            c
    #define INT64_C(c)	            c ## LL
    
    #define UINT8_C(c)	            c ## U
    #define UINT16_C(c)	            c ## U
    #define UINT32_C(c)	            c ## U
    #define UINT64_C(c)	            c ## ULL
    
    #define INTMAX_C(c)	            c ## LL
    #define UINTMAX_C(c)	        c ## ULL
    
#endif

_END_STD_C

#endif
